#ifndef CLIPBOARDHANDLER_H
#define CLIPBOARDHANDLER_H

#include <QObject>
#include <QClipboard>
#include <QGuiApplication>
#include <QDebug>

class ClipboardHandler : public QObject
{
    Q_OBJECT
public:
    explicit ClipboardHandler(QObject *parent = nullptr)
    {
        clipboard = QGuiApplication::clipboard();
        connect(clipboard, &QClipboard::dataChanged, this, &ClipboardHandler::onClipboardChanged);//链接剪切板便函的消息和相关槽函数
    }
    Q_INVOKABLE QString getClipboardText(){
        return clipboard->text();
    }

    Q_INVOKABLE void setClipboardText(QString text){
        clipboard->setText(text);
    }

signals:
    void clipboardChanged(QString text);
private slots:
    void onClipboardChanged();
private:
    QClipboard *clipboard;
};

#endif // CLIPBOARDHANDLER_H
